package com.mc.stack;

import java.util.Stack;
/**
 * 判断输入序列是否能够满足出栈序列
 * @author MC
 *
 */
public class PopSeries {
	
	private int[] pushArray;
	private int[] popArray;
	
	public PopSeries(int[] push, int[] pop){
		this.pushArray = push;
		this.popArray = pop;
	}
	public boolean isMatch(){
		int i=0;
		int j=0;
		Stack<Integer> sup = new Stack<Integer>();
		while(i<=pushArray.length){
			if(sup.isEmpty()||sup.peek()!=popArray[j]){
				if(i==pushArray.length)
					break;	
				sup.push(pushArray[i++]);
			}
			else{
				sup.pop();
				j++;
			}
		}
		if(j!=popArray.length)
			return false;
		return true;
	}
	public static void main(String[] args) {
		PopSeries p = new PopSeries(new int[]{1,2,3,4,5}, new int[]{5,4,3,2,1});
		System.out.println(p.isMatch());
	}
}
